/*
 * @lc app=leetcode.cn id=69 lang=javascript
 *
 * [69] x 的平方根
 */

// @lc code=start
/**
 * @param {number} x
 * @return {number}
 */
var mySqrt = function(x) {
    if(x==1||x==0){return x}
    let left=0
    let right=x>>1
    let mid=(left+right)>>1
    while(left<=right){
        if(mid*mid===x){return mid}
        if(mid*mid<x){left=mid+1;}
        if(mid*mid>x){right=mid-1;}
        mid=(left+right)>>1
    }
    if(left*left>x){return left-1}
    return left
};
// @lc code=end

